import java.util.Arrays;
import java.util.Comparator;

public class SolutionInterview8_13 {
    public int pileBox(int[][] box) {
        int[] f=new int[box.length];
        Arrays.sort(box, Comparator.comparingInt(a -> a[0]));
        for (int i=0;i<box.length;i++){
            for (int j=0;j<i;j++){
                if (box[j][0]<box[i][0] && box[j][1]<box[i][1] && box[j][2]<box[i][2]){
                    f[i]=Math.max(f[i],f[j]);
                }
            }
            f[i]+=box[i][2];
        }
        return Arrays.stream(f).max().getAsInt();
    }

    public static void main(String[] args) {
        System.out.println(new SolutionInterview8_13().pileBox(new int[][]{{1,1,1},{2,2,2},{3,3,3}}));
    }
}
